<!DOCTYPE html>
<html lang="en">

  <head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
  </head>

  <body>
    <script>
      /*
            es5中的继承的实现，比较复杂
            es6里面进行了简化
                class + extends
        */

      /*
          class - 关键字 - 声明类型

              class 类名 {
                  constructor(属性值){
                      this.属性名 = 属性值
                  }
                  方法名(参数){
                      方法体
                  }
              }
      */

      class Person {
        constructor(name, age, gender) {
          this.name = name
          this.gender = gender
          this.age = age
        }
        sayHi() {
          console.log(`你好,我叫${this.name}`);
        }
      }

      // let p1 = new Person('狗蛋', 16, '男')
      // p1.sayHi()
      // console.log(p1);

      /*
          extends - 关键字 - 实现 class 的 继承的

          用法：
              class 子类 extends 父类 {
                  constructor(属性值){
                      super(参数)
                      this.属性名 = 属性值
                  }
                  方法名(){}
              }
      */

      class Student extends Person {
        constructor(name, age, gender, number) {
          super(name, age, gender) // super,相当于借用构造函数实现属性复用
          this.number = number
        }
        doHomeWork() {
          console.log('我正在做作业');
        }
      }

      let s1 = new Student('翠花', 12, '女')
      console.log(s1);
      s1.sayHi() //你好，我叫翠花
      s1.doHomeWork() //我正在做作业

      Object.prototype.run = function () {
        console.log('run方法调用了')
      }

     
    </script>
  </body>

</html>